﻿using System;
using Balloonerds.Algebra;

namespace RayTracer
{
    public class Surface
    {
        public Func<Vector, Color> Diffuse { get; set; }
        public Func<Vector, Color> Specular { get; set; }
        public Func<Vector, double> Shininess { get; set; } //Phong exponent
        public Func<Vector, Color> Reflection { get; set; }

        public static Surface Metallic(Color color)
        {
            return new Surface()
            {
                Diffuse = pos => color * .7,
                Specular = pos => Color.White,
                Shininess = pos => 100,
                Reflection = pos =>color * .8
            };
        }
        public static Surface Shiny(Color color)
        {
            return new Surface()
            {
                Diffuse = pos => color * .9,
                Specular = pos => Color.White,
                Shininess = pos => 100,
                Reflection = pos => color * .1
            };
        }
        public static Surface Matte(Color color)
        {
            return new Surface()
            {
                Diffuse = pos => color,
                Specular = pos => Color.Black,
                Shininess = pos => 50,
                Reflection = pos => Color.Black
            };
        }

        public static Surface CheckeredXZ(double size)
        {
            return new Surface()
            {
                Diffuse = pos => ((Math.Floor(pos.Z / size) + Math.Floor(pos.X / size)) % 2 != 0) ? Color.White * .6 : Color.White * .1,
                Specular = pos =>  Color.White * .7,
                Shininess = pos => 50,
                Reflection = pos => Color.White * .1
            };
        }

        public static readonly Surface Gold = Surface.Metallic(Color.FromWMColor(System.Windows.Media.Colors.Gold));
        public static readonly Surface Silver = Surface.Metallic(Color.FromWMColor(System.Windows.Media.Colors.Silver));
        public static readonly Surface Copper = Surface.Metallic(Color.FromWMColor(System.Windows.Media.Color.FromRgb(218, 138, 103)));
        public static readonly Surface Steel = Surface.Metallic(Color.FromWMColor(System.Windows.Media.Colors.LightSteelBlue));
        public static readonly Surface Pyrite = Surface.Metallic(Color.FromWMColor(System.Windows.Media.Colors.LightGoldenrodYellow));
    }
}
